{include file="public/header" /}
<body class="gray-bg">
<div class="wrapper wrapper-content">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>添加</h5>
                </div>
                <div class="ibox-content layui-form">
                    <div class="layui-row layui-col-space10 layui-form-item ">

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <label class="layui-form-label">关键词：</label>
                            <div class="layui-input-block">
                                <input type="text" name="search_word" lay-verify="required" placeholder="关键词" class="layui-input" maxlength="200">
                            </div>
                        </div>

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8 form-group">
                            <label class="layui-form-label">类型：</label>
                            <div class="layui-input-block">
                                <select name="search_type" lay-filter="role">
                                    <option value="1" selected>分类</option>
                                    <option value="2" >热门</option>
                                </select>
                            </div>
                        </div>

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8" id="f_cate">
                            <label class="layui-form-label">一级分类：</label>
                            <div class="layui-input-block">
                                <select name="search_f_id"  xm-select-search="" xm-select-radio="" xm-select-search-type="dl" lay-search="" id="goods_f_id"  lay-filter="goods_f_id">
                                    <option value="" >---- 一级分类 ----</option>
                                    {foreach name="f_cate" item="v1"}
                                    <option value="{$v1.cate_id}" >{$v1.cate_name}</option>
                                    {/foreach}
                                </select>
                            </div>
                        </div>

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8" id="s_cate">
                            <label class="layui-form-label">二级分类：</label>
                            <div class="layui-input-block">
                                <select name="search_s_id"  xm-select-search="" xm-select-radio="" xm-select-search-type="dl" lay-search=""  id="goods_s_id"  lay-filter="goods_s_id">
                                    <option value="" >---- 二级分类 ----</option>

                                </select>
                            </div>
                        </div>

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8" id="cate_goods">
                            <label class="layui-form-label">分类商品：</label>
                            <div class="layui-input-block">
                                <select name="cate_goods" xm-select="select2" xm-select-search="" id="cate_good">
                                    <option value="" >---- 商品 ----</option>
                                </select>
                            </div>
                        </div>

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8 hidden" id="hot_goods">
                            <label class="layui-form-label">热门商品：</label>
                            <div class="layui-input-block">
                                <select name="hot_goods"  xm-select="select1" xm-select-search="">
                                    <option value="" >选择热门商品</option>
                                    {foreach name="hot_goods" item="v1"}
                                    <option value="{$v1.goods_id}" >{$v1.goods_name}</option>
                                    {/foreach}
                                </select>
                            </div>
                        </div>

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <div class="layui-input-block">
                                <button class="layui-btn" lay-submit="" lay-filter="component-form-element">添加
                                </button>
                                <button class="layui-btn layui-btn-primary" onclick="history.go(-1)">关闭</button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
{include file="public/footer" /}
<script>
//    var editor = wk.wang({elem:'#LAY_editor'});
//    wk.uploadImg({size:5,type:'png,jpg,jpeg',url:"{:url('Upload/upload')}",domain:""});
    layui.use(['form','upload','layedit'], function() {
        var form = layui.form;
//        form.verify({
//            editor:function(value,item){
//                if(editor.txt.html() == '<p><br></p>'){
//                    return '请填写内容';
//                }
//            }
//        });
        form.on('submit(component-form-element)', function (data) {
//            data.field.new_content = editor.txt.html();
            $('.layui-btn').addClass('layui-disabled').attr('disabled','disabled');
            $.ajax({
                url:"{:url('add')}",
                type:'post',
                dataType:'json',
                data:data.field,
                success:function(res){
                    if (res.code == 200) {
                        wk.success(res.msg,"{:url('Search/index')}")
                    } else {
                        wk.error(res.msg,'','$(".layui-btn").removeClass(\'layui-disabled\').removeAttr(\'disabled\');');
                    }
                }
            })
        });
        form.on('select(role)', function(data){
            if(data.value == 1){
                $("#f_cate").removeClass('hidden');
                $("#s_cate").removeClass('hidden');
                $("#cate_goods").removeClass('hidden');
                $("#hot_goods").addClass('hidden');
            }else{
                $("#f_cate").addClass('hidden');
                $("#s_cate").addClass('hidden');
                $("#cate_goods").addClass('hidden');
                $("#hot_goods").removeClass('hidden');
            }
        });
    });
</script>
<script>
    // 根据二级分类获取商品
    //layui分类
    layui.use(['form'], function() {
        var form = layui.form
                , layer = layui.layer
        form.on('select(goods_s_id)', function(data){
            getGoods(data.value);
        });
        function getGoods(id){
            $.ajax({
                url:"{:url('admin/Base/cateGoods')}",
                dataType:"json",
                data:'id='+id,
                type:'post',
                success:function(res){
                    layui.formSelects.data('select2', 'local', {
                        arr: res.msg
                    });
                }
            })
        }
    })
</script>

</body>
</html>
